package com.wva.common.config;

import com.alibaba.ttl.threadpool.TtlExecutors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;

/**
 * 配置Spring Async注解使用的线程池为自定义线程池
 * @Author: hong
 * @Date: 2025/2/12 19:38:36
 */
@Component
public class AsyncConfig implements AsyncConfigurer {
    //注入spring线程池
    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    //装饰spring默认线程池为ttl线程池
    @Override
    public Executor getAsyncExecutor() {
        return TtlExecutors.getTtlExecutor(threadPoolTaskExecutor);
    }
}
